package cn.kgc.service;

import cn.kgc.config.RabbitMqConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
@Slf4j
public class ConsumerService {


    //创建两个监听--sms队列
    //监听短信队列
    @RabbitListener(queues = {RabbitMqConfig.QUEUE_INFORM_SMS})
    public void receive_sms(String msg, Message message, Channel channel) throws IOException {
        //deliveryTag 每一条Rabbitmq中的消息，都有一个标签，tag,唯一的，rabbitmq生成的消息的唯一的标志
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try{
            log.info("消费者1读取到的消息======="+msg);
                //几个消息一起确认 deliveryTag=3
            int i=0;
            i=4/i;
            log.info("消费者确认消息");
            channel.basicAck(deliveryTag,true);
        }catch (Exception e){
             log.info("消费者出现异常了");
             channel.basicNack(deliveryTag,true,false);
             throw e;
        }
    }
//
//
//    //监听 ---email队列
//    //监听email队列
//    @RabbitListener(queues = {RabbitMqConfig.QUEUE_INFORM_EMAIL})
//    public void receive_email(String msg, Message message, Channel channel){
//        log.info("消费者2读取到的消息======="+msg);
//    }
//





}
